IDLgrFont

A font object represents a typeface, style, weight, and point size that may be associated with text objects.

Creating Font Objects

Fonts used by font objects are specified in a string constant constructed from a font name and one or more optional modifiers. When you create a font object, assign the font name string to the NAME property or use it as the IDLgrFont::Init Fontname argument.

Specifying a TrueType Font

The font name is the name by which your computer system knows the font (Times for the Times Roman font, for example). Modifiers specify the weight, angle, and other attributes of the font (bold specifies a weight, italic an angle). The font name string looks like this:

'fontname*weight*angle*other_modifiers'

where other_modifiers can be any other font property supported by a given font, such as a slant. For example, the font name string for Helvetica bold italic is:

'helvetica*bold*italic'

The font name string for Times Roman Regular is:

'times'

While the font name must come first in the font name string, the order in which the modifiers are specified is not important. The following statement creates a font object using a bold version of the Times Roman font, with a size of 20 points by replacing the Fontname argument with 'times*bold':

myFont = OBJ_NEW('IDLgrFont', 'times*bold', SIZE=20)

Specifying a Hershey Vector Font

To create a font object using a vector Hershey font, use a string of the format Hershey*fontnum where fontnum is the Hershey font’s index number. The following statement creates a font object using the Duplex Roman Hershey font, with a size of 14 points:

myHersheyFont = OBJ_NEW('IDLgrFont', NAME='hershey*5', SIZE=14)

Assigning a Font Object to a Text Object

To use a font object, use the FONT keyword in the IDLgrText::Init method (or change the text object’s font via the SetProperty method):

myText = OBJ_NEW('IDLgrText', 'Ay, Carumba', FONT = myFont)

or

myText->SetProperty, STRING='Angstrom symbol: ' + STRING("305B), $

FONT=myHersheyFont

This last example prints the Angstrom symbol by specifying an octal code. If no font object is specified, IDL uses the default font—12 point Helvetica.

Object Graphics Embedded Formatting Examples

Embedded formatting commands are in-line commands that allow you to position text and change fonts within a single line of text. The following examples use both the positioning commands and the font selection commands. All available embedded formatting commands are listed in Embedded Formatting Commands.

Tip: Set the ENABLE_FORMATTING property on the IDLgrText object to use formatting commands in Object Graphics.

This example applies embedded formatting commands that control text positioning.

oText = OBJ_NEW('IDLgrText', /ENABLE_FORMATTING)

oText->SetProperty, STRING='!LLower!S!EExponent!R!IIndex' + $

'!N Normal!S!EExp!R!IInd!N!S!U Up' + $

' !R!D Down!N!S!A Above!R!B Below'

XOBJVIEW, oText

You can also change what fonts are used within the text string. For example, you can use the special math symbols available in the Hershey vector font character set (Font 9). When you use the !M formatting command, this applies the font change to the single character immediately following the !M. Subsequent characters return to the preceding font. The following example produces the same equation as that shown in A Complex Equation.

; String to produce equation:

SS = '!6F(s) = (2!4p)!e-1/2!n !mi!s!a!e!m' + STRING("44B) +$

'!r!b!i ' + '-!m' + STRING("44B) + $

'!nF(x)e !e-i2!4p!3xs!ndx'

myHersheyFont = OBJ_NEW('IDLgrFont', NAME='hershey*5', SIZE=24)

otext = OBJ_NEW('IDLgrText', /ENABLE_FORMATTING)

oText->SetProperty, STRING=ss, FONT=myHersheyFont

XOBJVIEW, oText

The font object in this example must use a Hershey font to create the desired results. If no font is specified, the default 12-point Helvetica (not a vector font) is used, and the formatting commands create a different result.

Superclasses

None

Creation

See IDLgrFont::Init.

Properties

Objects of this class have the following properties. See IDLgrFont Properties for details on individual properties.

In addition, objects of this class inherit the properties of all superclasses of this class.

Methods

This class has the following methods:

In addition, this class inherits the methods of its superclasses (if any).

Version History

5.0

Introduced

6.2

Added UVALUE property